package com.cqupt.scanning.system.file.helper;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * IO流转换类
 * @Data: 2021/7/7 18:42
 * @Author: 宋宝梁
 */
public class StreamConvert {
    /**
     * 输入流转字节数组
     * @param input
     * @return
     */
    public static byte[] InputStreamToByte(InputStream input) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024*4];
        int n = 0;
        while (true) {
            try {
                if (-1 == (n = input.read(buffer))) break;
            } catch (IOException e) {
                e.printStackTrace();
            }
            output.write(buffer, 0, n);
        }
        return output.toByteArray();
    }
}
